import { type BaseListResp, type BaseResp } from '#/api/model/baseModel';
import { requestClient } from '#/api/request';

import {
  type ApiAuthorityItem,
  type ApiAuthorityReq,
  type MenuAuthorityReq,
  type MenuAuthorityResp,
} from './model/authority';

enum Api {
  GetauthorityApiById = '/sys-api/authority/api/role',
  GetauthorityMenuById = '/sys-api/authority/menu/role',
  UpdateauthorityApi = '/sys-api/authority/api/create_or_update',
  UpdateauthorityMenu = '/sys-api/authority/menu/create_or_update',
}

/**
 * @description: Get AuthorityApi  ById
 */
export const getAuthorityApiById = (roleId: number) => {
  return requestClient.get<BaseListResp<ApiAuthorityItem>>(
    `${Api.GetauthorityApiById}/${roleId}`,
  );
};
/**
 * @description: Get AuthorityMenu  ById
 */
export const getAuthorityMenuById = (roleId: number) => {
  return requestClient.get<MenuAuthorityResp>(
    `${Api.GetauthorityMenuById}/${roleId}`,
  );
};

/**
 * @description  updateAuthority  Api
 */
export const updateAuthorityApi = (data: ApiAuthorityReq) => {
  return requestClient.post<BaseResp>(Api.UpdateauthorityApi, data);
};

/**
 * @description  updateAuthority  Menu
 */
export const updateAuthorityMenu = (data: MenuAuthorityReq) => {
  return requestClient.post<BaseResp>(Api.UpdateauthorityMenu, data);
};
